package cn.keking.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import cn.keking.model.ReturnResponse;

@RestController
public class LoginController {
	
	  	@RequestMapping(value = "checkLogin")
	    public String checkLogin(HttpServletRequest request,HttpSession session, String email, String pwd) throws JsonProcessingException{
	    	if("admin@qq.com".equals(email) && "bAea42daDc2504d1".equals(pwd)){
	    		session.setAttribute("isLogin", true);
	    		return new ObjectMapper().writeValueAsString(new ReturnResponse<String>(0, "SUCCESS", null));
	    	}
	    	session.setAttribute("isLogin", false);
	    	return new ObjectMapper().writeValueAsString(new ReturnResponse<String>(1, "FAILURE", null));
	    }
	  	
	  	@RequestMapping(value = "logout")
	    public String logout(HttpServletRequest request,HttpSession session) throws JsonProcessingException{
	    	session.setAttribute("isLogin", false);
	    	return new ObjectMapper().writeValueAsString(new ReturnResponse<String>(0, "SUCCESS", null));
	    }
}
